// 封装本地存储的操作

const TOKEN_NAME = 'userToken'
const CHANNEL_NAME = 'userChannel'
const SEARCH_HISTORY_NAME = 'userSearchList'

export const setStorageToken = (payload) => {
  localStorage.setItem(TOKEN_NAME, JSON.stringify(payload))
}

export const getStorageToken = () => {
  return JSON.parse(localStorage.getItem(TOKEN_NAME)) || {}
}

export const removeStorageToken = () => {
  localStorage.removeItem(TOKEN_NAME)
}

export const setStorageChannel = (payload) => {
  localStorage.setItem(CHANNEL_NAME, JSON.stringify(payload))
}

export const getStorageChannel = () => {
  // 获取本地存储的频道数据
  // 如果没有数据，就去请求数据
  return JSON.parse(localStorage.getItem(CHANNEL_NAME))
}

// 存搜索的历史记录
export function setStorageSearchHistory(payload) {
  localStorage.setItem(SEARCH_HISTORY_NAME, JSON.stringify(payload))
}

export function getStorageSearchHistory() {
  return JSON.parse(localStorage.getItem(SEARCH_HISTORY_NAME)) || []
}
